package servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 转发/重定向定位练习
 */
public class UserServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        System.out.println("UserServlet 完成转发...");
        //通过转发定位/views/user/user.html文件
//        req.getRequestDispatcher("/views/user/user.html").forward(req, resp);

        System.out.println("UserServlet 完成重定向...");
        //通过重定向定位/views/user/user.html文件
        //重定向发生在浏览器
        resp.sendRedirect("views/user/user.html");
    }
}
